<template>
<table>
    <tr>
        <td>投资项目名称</td>
        <td><input type="text" placeholder="请输入投资项目名称" v-model="info.Iname"></td>
    </tr>
    <tr>
        <td>总额度</td>
        <td><input type="text" placeholder="请输入总额度" v-model="info.Isum"></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="提交" @click="AddInvest">
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref}from 'vue'
const info=ref(
    {
        Iname:'',
        Isum:''
    }
)
const AddInvest=()=>{
    if(info.value.Iname==''){
        alert("请输入投资项目名称")
        return
    }
    if(info.value.Isum==''){
        alert("请输入总额度")
        return
    }
    if(isNaN(Number(info.value.Isum))){
        alert("总额度必须为数字")
        return
    }
    if(Number(info.value.Isum)<=0||Number(info.value.Isum)>=100000000000){
        alert("投资总金额需大于0元且小于1千万")
        return
    }
    axios.post('https://localhost:44368/api/Lx/AddInvest',
        {
            Iname:info.value.Iname,
            Isum:info.value.Isum
        }
    )
    .then(res=>{
        if(res.data>0){
            alert('添加成功')
            return
        }
        else if(res.data==-1){
            alert('项目已经存在,添加失败')
            return
        }
    })
}

</script>